Add Copyright class and copyright_diff() #82 #83 - #85
Conversation
* Create 'Copyright' class. * Add 'Copyright' to 'File' object. * Add empty lists for 'copyrights' and 'licenses' fields to 'File.to_dict()'. * Add new tests, fix failing tests. Signed-off-by: John M. Horan <johnmhoran@gmail.com>
* Add copyright_diff(). * Refactor license_diff(). * Add new tests and related test old/new scan pairs. Signed-off-by: John M. Horan <johnmhoran@gmail.com>
Signed-off-by: John M. Horan <johnmhoran@gmail.com>
| i.score += 15 | ||
| if delta.new_file.licenses == [] and len(delta.old_file.licenses) > 0: | ||
| delta.factors.append('license info removed') | ||
| delta.score += 15 |
There was a problem hiding this comment.
We should make a method that down
There was a problem hiding this comment.
Turn this logic into a function where you pass a score and a string. Then we can replace lines like 207 and 208 with a single function call instead of two line tweaks
There was a problem hiding this comment.
Add tests for this as well
| if delta.new_file.copyrights == [] and len(delta.old_file.copyrights) > 0: | ||
| delta.factors.append('copyright info removed') | ||
| delta.score += 10 | ||
| return |
There was a problem hiding this comment.
Probably best that we score these the same. This will also allow for you to combine the logic into a single if statement
|
|
||
| if ((new_statements != old_statements) or | ||
| (new_holders != old_holders) or | ||
| (new_authors != old_authors)): |
There was a problem hiding this comment.
I think we should ignore looking at copyright authors for now unless we have a good reason to use them.
Also I believe we need to rely more on holders. This needs some thought though
There was a problem hiding this comment.
@MaJuRG I've made this change -- let me know when you'd like to discuss how we could place greater reliance on holders.
| self.statements = dictionary.get('statements') | ||
| self.holders = dictionary.get('holders') | ||
| self.authors = dictionary.get('authors') | ||
|
|
There was a problem hiding this comment.
Like I mentioned above, lets remove authors.
| 'file' dictionary. | ||
| """ | ||
| def __init__(self, dictionary={}): | ||
| self.statements = dictionary.get('statements') |
There was a problem hiding this comment.
If you haven’t already, you should add tests cases where a files have large numbers of copyrights holders and statements to see if we choke somewhere, espically in the output
There was a problem hiding this comment.
Also tests where there are strange characters or accent marks in the copyright statements/holders.
All of these additional test cases I mentioned should probably come from scancode generated output directly as opposed to crafting the test object by hand.
There was a problem hiding this comment.
@MaJuRG Since we want to use ScanCode-generated output, do you have any codebases in mind that satisfy the characteristics you describe?
I've started to work my way through the codebases we've worked with (openssl, zlib et al.) but I've not yet seen large numbers of copyright holders/statements or unusual characters.
There was a problem hiding this comment.
@johnmhoran You will probably just have to hand-create a file or files that contain a bunch of copyright statements
There was a problem hiding this comment.
@MaJuRG I'm finding that an error is thrown when I include a French accent character in the copyright statements or holders value, e.g., "é". The error is thrown even if I comment out the character (presumably because even comments are parsed). Unicode and UTF-8 do not throw an error.
...
"statements": [
"U+00E9",
"\xc3\xa9"
# "é"
...
SyntaxError: Non-ASCII character '\xc3' in file C:\code\nexb\dev\deltacode\tests\test_models.py on line 1073, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
While PEP 263 gives some suggestions, it's not clear to me how we can apply these to handle our input. I've done some searching in the ScanCode repo -- surely ScanCode must be able to handle such characters -- but have not yet found how ScanCode addresses this.
There was a problem hiding this comment.
Looks like this issue might be addressed in scancode-toolkit/src/commoncode/text.py?
There was a problem hiding this comment.
@johnmhoran where is this "statements" located?
There was a problem hiding this comment.
@MaJuRG Would it be easier for you if I commit and push? Except for this one failing test, it's ready for your review.
* Add scoring method to Delta -- Delta.add_score().
* Call new scoring method from DeltaCode.license_diff() and
DeltaCode.copyright_diff().
* Add tests for Delta.add_score().
* Modify score for 'copyright info added'.
* Remove references to copyright authors.
* Add tests cases where a files have large numbers of copyright
holders and statements.
* Add tests cases where a files have unusual characters -- but errors
thrown with French accent characters.
Signed-off-by: John M. Horan <johnmhoran@gmail.com>
| if len(delta.new_file.licenses) > 0 and delta.old_file.licenses == []: | ||
| delta.factors.append('license info added') | ||
| delta.score += 20 | ||
| delta.add_score(20, 'license info added') |
There was a problem hiding this comment.
This needs to be renamed to something like delta.update.
We are not only adding to the score, we are also adding to factors etc and possibly more in the future.
| def add_score(self, score=0, factor=''): | ||
| """ | ||
| For each Delta object identified in DeltaCode.license_diff() or | ||
| DeltaCode.copyright_diff(), add the score to the object's 'score' |
There was a problem hiding this comment.
We do not need ot mention these funtions here. Simply tell me what this update function does.
| self.factors = [] | ||
| self.score = score | ||
|
|
||
| def add_score(self, score=0, factor=''): |
There was a problem hiding this comment.
like stated above, this needs to be renamed to update.
Signed-off-by: John M. Horan <johnmhoran@gmail.com>
|
@MaJuRG Done except for the question of how to test unusual characters like the French |
|
@johnmhoran I do not know the best way. Have you:
I ask because I dont really have a context to the error above and therefore cannot point you in the right direction. |
|
For example, scancode results may handle things like this implicitly, and we do not need to worry about it. OR it could be that we need to sanitize these strings at some point along the line depending on what operations we are performing. Unfortunately, this is a side effect of python2 specific problems w.r.t strings and character encodings. It may be that we push that particular issue off in favor of python3 migration, but we need more details. We may not care at all. More research on your part is always something you can do as well; I will not be able to really provide specific code examples etc until late weds or thurs |
|
@MaJuRG Understood. I did a fair amount of research but couldn't figure out how to apply it to the DeltaCode/ScanCode context. However, thinking about the process, I expect that my prior approach -- hand-crafting the input inside the test itself -- meant that any existing ScanCode/commoncode remediation was not encountered by the input. I like your suggestion -- will create separate files, scan with ScanCode and use for testing. |
* Added scans and tests for unusual characters like French and German
letters with accent marks.
Signed-off-by: John M. Horan <johnmhoran@gmail.com>
Signed-off-by: John M. Horan <johnmhoran@gmail.com>
Addresses issues #82 and #83, both of which are partial implementations of #43.